#include<stdio.h>
#include<stdlib.h>


int main()
{
	FILE *in,*out;
	char infile[20],outfile[20],ch;
	int character,space,digit,other;
	char str[50];
	character=space=digit=other=0;
	printf("Enter infile name\n");
	scanf("%s",infile);
	printf("Enter outfile name\n");
	scanf("%s",outfile);

	//打开文件
	if((in=fopen(infile,"r"))==NULL)
	{
		printf("fopen %s error!\n",infile);
		exit(0);
	}
	if((out=fopen(outfile,"w"))==NULL)
	{
		printf("fopen %s error!\n",outfile);
		exit(0);
	}

	//读取文件1内容进行统计
	ch=fgetc(in);
	while(ch!=EOF)
	{
		if(ch>='a'&&ch<='z' || ch >='A'&&ch<='Z')
		{
			character++;
		}
		else if(ch>='0'&&ch<='9')
		{
			digit++;
		}
		else if(ch==' ')
		{
			space++;
		}
		else
		{
			other++;
		}
		ch=fgetc(in);
	}
	
	//关闭输入文件·
	fclose(in);

	//将统计结果录入文件2中
	snprintf(str,50,"character:%d space:%d digit:%d other:%d\n",character,space,digit,other);
	fputs(str,out);
	//fseek(out,0L,0);
	//fprintf(out,"character:%d space:%d digit:%d other:%d\n",character,space,digit,other);
	//关闭输出文件·
	fclose(out);
	return 0;
}
